package com.bdqn.t330.ch03.controller;


import com.bdqn.t330.ch03.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("/user")
    public Object getUser(Long id) {
        System.out.println("id:" + id);
        return userService.getUserByIdBiz(id);
    }

    @RequestMapping("/delete")
    public Object deleteById(Long id) {
        System.out.println("id:" + id);
        Map<String, Boolean> map = new HashMap();
        try {
            userService.deleteById(id);
            map.put("result", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("result", false);
        }
        return map;
    }
}
